package com.example.service.impl;

import com.example.common.result.Result;
import com.example.common.result.YiFeiException;
import com.example.entity.dto.PojoDto;
import com.example.entity.yifei.Cmsmw;
import com.example.mapper.CmsmwMapper;
import com.example.service.CmsmwService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author LiangPandeng
 * @since 2024-02-26
 */
@Service
public class CmsmwServiceImpl extends ServiceImpl<CmsmwMapper, Cmsmw> implements CmsmwService {

    @Resource
    private CmsmwMapper cmsmwMapper;

    @Override
    public Result query(PojoDto pojoDto) {
        try {
            Map<String,Object> map =new HashMap<>();
            PageHelper.startPage(pojoDto.getCurrent(),pojoDto.getSize());
            List<Cmsmw> cmsmwIPage = this.cmsmwMapper.query(pojoDto);
            PageInfo<Cmsmw> pageInfo = new PageInfo<>(cmsmwIPage);
            map.put("page",pageInfo.getPages());
            map.put("data",pageInfo.getList());
            map.put("total",pageInfo.getTotal());
            return Result.ok(map);
        }catch (Exception e){
            throw new YiFeiException(500,"分页发生异常");
        }
    }


}
